home *** CD-ROM | disk | FTP | other *** search
- #include "relay.h"
-
- int formedit( struct datatable t[], struct window win )
-
- /* This function controls cursor movement within a form being edited. */
- /* Parameters: t[] an array of datatable structures containing the */
- /* information required to build the form on screen. */
- /* win a window structure containing data about the window for */
- /* the form in t[]. */
- /* Return value: key an int corresponding to a key that terminated editing */
- /* of the form. */
-
- {
-
- int i = 0, j = 0, kontinue, maxx = 0 , formlength, key = 0;
- char c, buff[10];
- struct datatable form[40];
-
- while( (t[i].descrip[0] != 'Q') &&
- (t[i].descrip[1] != 'Q') &&
- (t[i].descrip[2] != 'Q')){
- while (t[i].type == 0) /* Copy t[] into form[] without titles. */
- i++;
- form[j++] = t[i++];
- maxx++;
- }
- formlength = i;
-
- _settextwindow( win.upl.x, win.upl.y, win.lowr.x, win.lowr.y);
- _setbkcolor(text.background);
- _clearscreen( _GWINDOW );
- _settextcolor(text.input);
-
- /***************************** Print form. *********************************/
-
- for (i = 0; i < formlength; i++){
- _settextposition( t[i].xtext, t[i].ytext );
- _outtext( t[i].descrip );
-
- switch(t[i].type){
- case 0: /* Title. */
- _settextposition(t[i].xtext, t[i].yinput + t[i].ytext );
- _outtext( t[i].indata );
- _settextposition( 1, 1 );
- break;
- case 1: /* Text field. */
- _settextposition(t[i].xtext, t[i].yinput + t[i].ytext );
- _outtext( t[i].indata );
- _settextposition( 1, 1 );
- break;
- case 2: /* Integer field. */
- sprintf( buff, t[i].format, atol(t[i].indata));
- _settextposition(t[i].xtext, t[i].yinput + t[i].ytext );
- _outtext( buff );
- break;
-
- case 3: /* Float field. */
- sprintf( buff, t[i].format, atof(t[i].indata));
- _settextposition(t[i].xtext, t[i].yinput + t[i].ytext );
- _outtext( buff );
- break;
- }
- }
-
- _settextcolor( text.helpc ); /* Print help line for form. */
- _settextposition( text.helpp, 2 );
- _outtext( win.helpbuf );
- _settextcolor( text.input );
-
- /******************************* Edit form. ********************************/
-
- i = 0;
- cursor(form[i], ON, win);/* Initialize cursor position to first field. */
- kontinue = TRUE;
- while(kontinue){ /* Get key. */
- c = getch();
- if ( (c >= 'a' && c <= 'z') || /* Test c to determine if it is */
- (c >= 'A' && c <= 'Z') || /* a letter, number, or '.'. */
- (c >= '0' && c <= '9') ||
- (c == '.') ){
- ungetch(c);
- strcpy( form[i].indata, intext( form[i], win ) );
- if (i != (maxx-1)){
- i++;
- cursor( form[i-1], OFF, win );
- }
- cursor( form[i], ON, win );
- _settextwindow( win.upl.x, win.upl.y, /* Reprint help line */
- win.lowr.x, win.lowr.y );
- _settextcolor( text.helpc );
- _settextposition( text.helpp, 2 );
- _setbkcolor(text.background);
- _outtext( win.helpbuf );
- _settextcolor( text.input );
- _setbkcolor(text.field);
- }
- switch(c){
- case '\r': /* Return or Tab key. */
- case '\t':
- if (i == maxx - 1)
- break;
- cursor( form[i], OFF, win );
- i++;
- cursor( form[i], ON, win );
- break;
-
- case '\0': /* Control character has been pressed. */
- c = getch();
- switch(c){
- case 'M': /* Left arrow. */
- case 'H': /* Up arrow. */
- if (i == 0) /* Move cursor to */
- break; /* previous field. */
- cursor( form[i], OFF, win );
- i--;
- cursor( form[i], ON, win );
- break;
- case 'K': /* Right arrow. */
- case 'P': /* Down arrow. */
- if (i == maxx - 1) /* Move cursor to next*/
- break; /* field. */
- cursor( form[i], OFF, win );
- i++;
- cursor( form[i], ON, win );
- break;
- case 'Q': /* Page Down. */
- kontinue = 0; /* Exit edit mode. */
- key = 1;
- break;
- case 'I': /* Page Up. */
- kontinue = 0; /* Exit edit mode. */
- key = 2;
- break;
- case 'v': /* Ctrl + Page Down */
- kontinue = 0; /* Exit edit mode. */
- key = 3;
- break;
- case 'G': /* Home */
- kontinue = 0; /* Exit edit mode. */
- key = 4;
- break;
- case 'O': /* End */
- kontinue = 0; /* Exit edit mode. */
- key = 5;
- break;
- }
- }
- }
- _settextwindow( win.upl.x, win.upl.y, win.lowr.x, win.lowr.y);
- _setbkcolor( text.background );
- i = j = 0;
- while( j < maxx ){
- while (t[i].type == 0)
- i++;
- strcpy(t[i].indata, form[j].indata);
- j++;
- i++;
- }
- return key;
- }
-
-
-